#include <iostream>

#include <glad/glad.h>
#include <GLFW/glfw3.h>



int main(int argc, char* argv[])
{
    printf("[DBG] Calling: %s\n\n", argv[0]);

    //! glfw库初始化
    if (!glfwInit())
        return -1;

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    /* Create a windowed mode window and its OpenGL context */
    GLFWwindow* window = glfwCreateWindow(800, 600, "HelloOpenGL", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    //! glfw将窗口的上下文设置为当前线程的上下文.
    glfwMakeContextCurrent(window);


    //! glad: 加载所有opengl函数指针
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        std::cout << "Failed to initialize GPU!\n";
        return -1;
    }

    //! 渲染循环
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */        
        glClearColor(0.2f, 0.3f, 0.2f, 1.0f); //状态设置
        glClear(GL_COLOR_BUFFER_BIT); //< 状态使用

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    
    return 0;
}